import common from "@/api/common/index";
import Vue from 'vue'
const state = {
  msg:"",
  enable:false,
  isActive:false,
};

const mutations = {
  SET_MSG: (state, msg) => {
    state.msg = msg
  },
  SET_ENABLE: (state, enable) => {
    Vue.set(state,'enable',enable)
  },
  SET_ISACTIVE: (state, isActive) => {
    Vue.set(state,'isActive',isActive)
  },
};

const actions = {
  setSuggestion({ commit }, msg){
    return new Promise((resolve, reject)=> {
      commit("SET_MSG", msg);
      resolve()
    }).catch(()=>{
      reject()
    });
  },
  setEnable({ commit,state }, enable){
    return new Promise((resolve, reject)=> {
      commit("SET_ENABLE", enable);
      commit("SET_ISACTIVE", enable);
      resolve()
    }).catch(()=>{
      reject()
    });
  },
  setIsActive({ commit,state }, isActive){
    return new Promise((resolve, reject)=> {
      commit("SET_ISACTIVE", isActive);
      resolve()
    }).catch(()=>{
      reject()
    });
  },
  setDocumentTemporary({ commit,state }, data){
    return new Promise((resolve, reject)=> {
      common.setDocumentTemporary(data.id,{suggestion:data.suggestion})
      commit("SET_MSG", data.suggestion);
      resolve()
    }).catch(()=>{
      reject()
    });
  },
  getDocumentTemporary({ commit,state }, id){
    return new Promise((resolve, reject)=> {
      common.getDocumentTemporary(id).then(res=>{
        commit("SET_MSG", res.data.suggestion);
      })
      resolve()
    }).catch(()=>{
      reject()
    });
  },
};
export default {
  namespaced: true,
  state,
  mutations,
  actions
};
